package main
import "./tutorial"
import "github.com/golang/protobuf/proto"
import "io/ioutil"
import "os"
import "fmt"
func main(){
	book := &tutorial.AddressBook{}

	p := tutorial.Person{
        Id:    proto.Int32(1234),
        Name:  proto.String("John Doe"),
        Email: proto.String("jdoe@gmail.com"),
        Phones: []*tutorial.Person_PhoneNumber{
                {Number: proto.String("555-4321"), Type: tutorial.Person_HOME.Enum()},
        },
	}

	 book.People = append(book.People,&p)

	in,err := proto.Marshal(book)
	if err != nil{
		fmt.Println(err)
	}

	ioutil.WriteFile("testp.txt",in,os.ModeAppend)

	out,err := ioutil.ReadFile("testp.txt")

	booknew := &tutorial.AddressBook{}
	if err := proto.Unmarshal(out,booknew);err !=nil{
		fmt.Println(err)
	}
	fmt.Println(booknew)
}
